﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class DamageCheck
    {
        public void CheckDamage(List<DestroyableObject> objList,DestroyableObject dObj, bool isPlayer, float dmgValue, GameController gc, bool stun, float chance)
        {
            foreach (DestroyableObject enemy in objList)
            {
                if (Physics.SpritesCollided(dObj.ObjectSprite, enemy.ObjectSprite) && dObj != enemy && (enemy is Player) == isPlayer)
                {
                    if (dObj is Character)
                    {
                        dmgValue = ((float)(Core.Rnd((int)dmgValue) + dmgValue) * (dObj as Character).StatModifier.DamageMultiplier);
                        enemy.TakeDamage((int)(dmgValue * (dObj as Character).StatModifier.DamageMultiplier), gc);
                    }
                    else
                        enemy.TakeDamage((int)dmgValue, gc);
                    if ((enemy is Character) && Core.Rnd() < chance)
                        (enemy as Character).Buffs.Add(new Stun((Character) enemy,true,GlobalConst.DefaultRow,GlobalConst.DefaultColEnd, GlobalConst.DefaultFPC,
                            0, "Stun", 1000, false));
                    if ((dObj is Player) && (dObj as Player).Power < (dObj as Player).MaxPower)
                        (dObj as Player).Power += (int)(dmgValue * (dObj as Character).StatModifier.DamageMultiplier);
                }
            }
        }

        public void CheckDamage(List<DestroyableObject> objList, DestroyableObject dObj, bool isPlayer, float dmgValue, GameController gc,
                int startPosX, int startPosY, int w, int h, bool stun, float chance)
        {
            foreach (DestroyableObject enemy in gc.GameStages.Peek().CharList)
            {
                if ((dObj is Player) && (dObj as Player).Power <= 0) return;
                if (Physics.SpriteRectCollision(enemy.ObjectSprite, startPosX, startPosY, w, h) && dObj != enemy && (enemy is Player) == isPlayer)
                {
                    if (dObj is Character)
                    {
                        dmgValue = ((float)(Core.Rnd((int)dmgValue) + dmgValue) * (dObj as Character).StatModifier.DamageMultiplier);
                        enemy.TakeDamage((int)(dmgValue * (dObj as Character).StatModifier.DamageMultiplier), gc);
                    }
                    else
                        enemy.TakeDamage((int)dmgValue, gc);
                    
                    if ((enemy is Character) && Core.Rnd() < chance)
                        (enemy as Character).Buffs.Add(new Stun((Character) enemy,true,GlobalConst.DefaultRow,GlobalConst.DefaultColEnd, GlobalConst.DefaultFPC,
                            0, "Stun", 1000, false));
                    if ((dObj is Player) && (dObj as Player).Power > 0)
                        (dObj as Player).Power -= 50;
                }
            }
        }

        public void CheckDamage(List<DestroyableObject> objList, Sprite dObj, bool isPlayer, float dmgValue, GameController gc, bool stun, float chance)
        {
            foreach (DestroyableObject enemy in objList)
                if (Physics.SpritesCollided(dObj, enemy.ObjectSprite) && (enemy is Player) == isPlayer)
                {
                    enemy.TakeDamage((int)dmgValue, gc);
                    if ((enemy is Character) && Core.Rnd() < chance)
                        (enemy as Character).Buffs.Add(new Stun((Character) enemy,true,GlobalConst.DefaultRow,GlobalConst.DefaultColEnd, GlobalConst.DefaultFPC,
                            0, "Stun", 1000, false));
                }
        }
    }
}

